﻿/*
 * TestLEDController.cs
 * Written by: Shawn Gilleland
 */

using IndicationLayer;
using Supply_Fetch;
using Supply_Fetch.MUILayer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPLayer
{
    class TestLEDController
    {
        private HardwareCommunicationGateway hwCommGate;
        public void TestLED(LED led)
        {
            if (led.State == Constants.ON)
            {
                hwCommGate.ConnectToSerialPort();
                if (hwCommGate.SerialPortIsOpen())
                {
                    hwCommGate.ActivateLED(led.ID);
                    hwCommGate.DisposeSerialPort();
                }
            }
            else
            {
                hwCommGate.ConnectToSerialPort();
                if (hwCommGate.SerialPortIsOpen())
                {
                    hwCommGate.DeactivateLED(led.ID);
                    hwCommGate.DisposeSerialPort();
                }
            }
        }

        public TestLEDController()
        {
            hwCommGate = new HardwareCommunicationGateway();
        }

        public void TurnAllLightsOff()
        {
            hwCommGate.ConnectToSerialPort();
            if (hwCommGate.SerialPortIsOpen())
            {
                this.hwCommGate.DeactivateAllDrawers();
                this.hwCommGate.DisposeSerialPort();
            }
        }

        public void CloseLightsApplication()
        {
            this.hwCommGate.CloseSerialPort();

            if (this.hwCommGate.SerialPortIsOpen())
            {
                this.hwCommGate.DeactivateAllDrawers();
                this.hwCommGate.CloseCommunicationPort();
            }
        }

        public void TurnAllLightsOn()
        {
            hwCommGate.ConnectToSerialPort();
            if (hwCommGate.SerialPortIsOpen())
            {
                this.hwCommGate.ActivateAllDrawers();
                hwCommGate.DisposeSerialPort();
            }
        }
    }
}
